package com.xuecheng.media.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.xuecheng.media.model.po.MediaProcess;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * <p>
 * Mapper 接口
 * </p>
 *
 * @author itcast
 */
@Mapper
public interface MediaProcessMapper extends BaseMapper<MediaProcess> {

    /**
     * 开启一个任务
     *
     * @param taskId
     * @return
     */
    @Update("update media_process mp set mp.status = '4' where (mp.status = '1' or mp.status = '3') and mp.fail_count <3 and mp.id = #{taskId}")
    public int startTask(@Param("taskId") Long taskId);

    @Select("select * from media_process mp where (mp.status = '1' or mp.status = '3') and mp.fail_count <3 and mp.id % #{shardTotal} = #{shardIndex} limit #{count}")
    public List<MediaProcess> selectListByShardIndex(@Param("shardTotal") int shardTotal, @Param("shardIndex") int shardIndex, @Param("count") int count);
}
